package com.auto.learning.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.auto.learning.R;
import com.auto.learning.bean.GradeItemBean;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class MyGradeAdapter extends BaseAdapter {
	
	private Context context;
	private List<GradeItemBean> list;
	public MyGradeAdapter(Context context,List<GradeItemBean> list){
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}
	ViewHolder holder;
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.mygrade_adapter, null);
			holder = new ViewHolder();
			holder.image_head = (ImageView) convertView.findViewById(R.id.image_head);
			holder.tv_grade_name = (TextView) convertView.findViewById(R.id.tv_grade_name);
			holder.tv_booknum = (TextView) convertView.findViewById(R.id.tv_booknum);
			holder.linear_main = (LinearLayout) convertView.findViewById(R.id.linear_main);
			holder.tv_keepbook_num = (TextView) convertView.findViewById(R.id.tv_keepbook_num);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		/*switch (position % 2) {
		case 0:
			holder.linear_main.setBackgroundColor(context.getResources().getColor(R.color.text_mygraade_color));
			break;
		case 1:
			holder.linear_main.setBackgroundColor(context.getResources().getColor(R.color.main_favor_background));
			break;
		}*/
		holder.tv_grade_name.setText(list.get(position).getGradeName()+"");
		holder.tv_booknum.setText(list.get(position).getUpgradeNum()+"本");
		holder.tv_keepbook_num.setText(list.get(position).getKeepNum()+"本");
		ImageLoader.getInstance().displayImage(list.get(position).getGradeImgUrl(), holder.image_head);
		return convertView;
	}
	
	public class ViewHolder{
		ImageView image_head;
		TextView tv_grade_name;
		TextView tv_booknum,tv_keepbook_num;
		LinearLayout linear_main;
	}
	
	

}
